using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

namespace Sailfish
{
    [FilePath("ProjectSettings/CreatEditorData.asset", FilePathAttribute.Location.ProjectFolder)]
    public class CreatEditorData : ScriptableSingleton<CreatEditorData>
    {
        public string resPath             = "Assets/Resources";
        public string streamPath          = "Assets/StreamingAssets";
        public string addressablePath     = "Assets/AddressableAssets";
        public string saveResPath         = $"Assets/Scripts/Auto/Engine/ResFolder.cs";
        public string saveTagsPath        = $"Assets/Scripts/Auto/Engine/TagAndLayer.cs";
        public string saveStreamPath      = $"Assets/Scripts/Auto/Engine/StreamFolder.cs";
        public string saveAddressablePath = $"Assets/Scripts/Auto/Engine/AddressFolder.cs";


        public void SaveAssets()
        {
            Save(true);
        }
    }

    class CreatEditorDataProvider : SettingsProvider
    {
        public CreatEditorDataProvider(string path, SettingsScope scope = SettingsScope.User) : base(path, scope) { }

        const int width = 150;

        public override void OnGUI(string searchContext)
        {
            base.OnGUI(searchContext);


            GUI.enabled = false;
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Res Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.resPath = EditorGUILayout.TextField(CreatEditorData.instance.resPath);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Stream Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.streamPath = EditorGUILayout.TextField(CreatEditorData.instance.streamPath);
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Addressable Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.addressablePath = EditorGUILayout.TextField(CreatEditorData.instance.addressablePath);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Save Res Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.saveResPath = EditorGUILayout.TextField(CreatEditorData.instance.saveResPath);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Save Tags Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.saveTagsPath = EditorGUILayout.TextField(CreatEditorData.instance.saveTagsPath);
            EditorGUILayout.EndHorizontal();


            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Save Stream Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.saveStreamPath = EditorGUILayout.TextField(CreatEditorData.instance.saveStreamPath);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Save Addressable Path", EditorStyles.boldLabel, GUILayout.Width(width));
            CreatEditorData.instance.saveAddressablePath = EditorGUILayout.TextField(CreatEditorData.instance.saveAddressablePath);
            EditorGUILayout.EndHorizontal();
   
        }

        [SettingsProvider]
        public static SettingsProvider CreateMyCustomSettingsProvider()
        {
            var provider = new CreatEditorDataProvider("Project/Sailfish/CreatEditorData", SettingsScope.Project);
            provider.keywords = GetSearchKeywordsFromGUIContentProperties<GUIContent>();
            return provider;
        }
    }
}
